#!/usr/bin/env node

const http = require('http'),
      fs = require('fs');

let data = require('./data.js');

let arr = [];
for(var i=0;i<data.length;i++){
  if(data[i].movieRange != '暂无评分'){
    arr.push(data[i]);
  }
}

function sortSize(a,b){
  return b.movieRange - a.movieRange;             
}
arr.sort(sortSize); 
console.log(arr);


http.createServer((req,res)=>{
  let html = fs.readFileSync('./index.html').toString('utf8');

  if(req.url === '/'){
    res.writeHead(200,{
      'Content-type':'text/html'          
    });
    res.end(html);   
  }
  else if(req.url === '/getlist'){
    res.end(JSON.stringify(arr));
  }
}).listen(8080);




